﻿<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>首页</title>
    <div th:replace="include/_head :: head"></div>
    <style>
        fieldset{
            font-size: 20px;
        }
        legend{
            font-size: 25px!important;
        }
    </style>
</head>

<body class="layui-bg-green">
<div class="layui-container" style="margin-top: 30px;">

    <div class="layui-row" style="text-align: center">
        <div class="layui-col-xs12">
            <div th:text="${nodeInfo}" style="font-size: 30px;"></div>
            <div style="text-align: right" id="serverTime"></div>
        </div>
    </div>
    <div class="layui-row" style="margin-top: 20px;">
        <div class="layui-col-xs12">
            <fieldset class="layui-elem-field">
                <legend>调度描述</legend>
                <div class="layui-field-box" th:text="${app.description}"></div>
            </fieldset>
            <fieldset class="layui-elem-field">
                <legend>ZK 信息</legend>
                <div class="layui-field-box">
                    <div th:text="|连接信息：${zk.connectString}|"></div>
                    <div th:text="|本节点在 ZK 上的 Key：${app.key} （表示此节点是 ${app.key} 集群上的一个）|"></div>
                </div>
            </fieldset>
            <fieldset class="layui-elem-field">
                <legend>Disruptor 调度信息</legend>
                <div class="layui-field-box">
                    <div th:text="|消费者线程数：${prop.consumerThreadNum}|"></div>
                    <div th:text="|环形队列大小：${prop.bufferSize}|"></div>
                    <div th:text="|调度周期：${loopTime}|"></div>
                    <div>生产者状态：<span th:if="${proStatus}">开启</span><span th:unless="${proStatus}">关闭</span></div>
                    <br/>
                    <button class="layui-btn layui-btn-warm" onclick="switchFun()">
                        <b>trigger</b>
                    </button>
                </div>
            </fieldset>
        </div>
    </div>
</div>
<script type="text/javascript" th:inline="javascript">

    var proStatus = [[${proStatus}]];
    var serverTime = [[${serverTime}]];


    $(document).ready(function () {
        changeTime();
        setInterval(changeTime,1000);
        element.init();
    });

    function switchFun(){
        var url = ctx;
        if (proStatus){
            url += "/stopProducer";
        }else {
            url += "/startProducer";
        }
        window.location = url;
    }


    function changeTime(){
        serverTime += 1000;
        var timeStr = datetimeFormat_1(serverTime);
        $("#serverTime").html(timeStr);
    }

    function test(){
        $.ajax({
            url:ctx+"/tx",
            dataType:"text",
            async:false,
            success:function(data){
                layer.msg(data);
            },
            error:function (XMLHttpRequest, textStatus, errorThrown){
                alert("系统异常，删除服务器配置失败！");
            }
        });
    }



</script>
</body>
</html>